import java.util.ArrayList;

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }
}

public class reversePrint {
    public int[] _reversePrint(ListNode head) {
        if (head == null)
            return new int[] {};

        ArrayList<Integer> ans = new ArrayList<>();
        while (head != null) {
            ans.add(head.val);
            head = head.next;
        }

        int[] res = new int[ans.size()];
        for (int i = 0; i < res.length; i++) {
            res[res.length - i - 1] = ans.get(i);
        }

        return res;
    }

}
